/**
 *	 defined the main entry program
 *   VisualGroup JavaScript prototype Classes, version draf
 *  (c) 2008 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/
/**
 * Defined The Base Object 
 */
Vsg = {
	Version: "0.0.1",
	date:"2009-04-06",
	ShowLoadClassTime:false,
	PROFILE:"app-profile",
	APP_LANGUAGE:"app-language",
	
	loadExtLibs:function(libsFileNames) {
		try {
			var $content = getRootScriptContent();
	
			var $importType = typeof( libsFileNames );
	
			if ($importType == "object" || $importType == "string") {
				if (libsFileNames instanceof Array) {
					for (var $i = 0 ; $i < libsFileNames.length ; $i++) {
						includeJavascriptSrc($content+"/js/lib/"+libsFileNames[$i]);
					}
				} else {
				
					includeJavascriptSrc($content+"/js/lib/"+libsFileNames);

				}

			}	

			
		} catch (e) {
			alert(e);
		}		
	},

	/**
	 * defined class name 
	 */
	importClass:function($className) {
		try {

			var $importType = typeof( $className );
	
			if ($importType == "object" || $importType == "string") {
				if ($className instanceof Array) {
					for (var $i = 0 ; $i < $className.length ; $i++) {
						if (this._importedClass.indexOf( $className[$i] ) == -1) {
							this._importedClass.push( $className[$i] );
						}
					}
				} else {
					if (this._importedClass.indexOf( $className ) == -1) {
						this._importedClass.push( $className );
					}
				}

			}	

			
		} catch (e) {
			alert(e);
		}
	},
	
	_importedClass:[],
	
	
	_initMethod:[],


	/**
 	* run the main program
 	*/
	run:function($fn) {
		
		var $urlContext = getRootScriptContent();
		
		var $importClasses = this._importedClass;
		

		
		// --- load the engine ---
		var $engine = VsEngineFactory.getEngine();
		$engine.onInit(function() {

			// --- add import class ---

			this.importClass( $importClasses );
			
			// --- run the engine ---
			
			this.run();
		
		},$engine);
		$engine.onReady( $fn , this);
		
	},
	
	_urlMaps : {},
	getURLKey : function( $key ) {
		alert($key);
		return "";
	},
	
	/**
	 * public method
	 * defined global name for event
	 * @param {Object} $name
	 * @param {Object} $fn
	 */
	_definedEvents : new Ext.util.MixedCollection(),
	definedEvent : function ($name ,  $fn) {
		this._definedEvents.add($name , $fn);
	},
	
	/**
	 * public method
	 * get the defined global name
	 * @param {Object} $name
	 */
	getDefinedEvent : function($name) {
		return this._definedEvents.key($name);
	},
	// --- defined global event helper ---
	EventHelper : new Ext.util.Observable(),
	
	_localeLang : {},
	
	// --- defined language mehtod ---
	getLanguage : function($key , $args) {
		
		var $localeLang = null;
		
		// --- defeind the key lange from cookie ----
		var $langServContext = Ext.state.Manager.get( Vsg.APP_LANGUAGE );
		try {
			$localeLang = Vsg._localeLang[$key];
			
			if ($langServContext != null && $localeLang == null) {
				// --- check the type ---
				$localeLang = $langServContext[$key];
			}
			
			if ($localeLang == null) {
				throw "did not defined locale language!";
			}
			
			// --- extend hanel defind ---
			if (typeof($localeLang) == "function") {
				
				// --- defined langcontext ---
				var $languageContext = {
					getKey: function($key) {
						var $subLangRef = Vsg._localeLang[$key];
						
						if ($langServContext != null && $subLangRef == null) {
							// --- check the type ---
							$subLangRef = $langServContext[$key];
						}
						
						// --- check the type of $subLangRef ---
						if ( typeof( $subLangRef ) == "function") {
							Ext.log("do not defined recursion for language key !");
							return "";
						}
						
						return $subLangRef;
					}
				};
				
				// --- call ref language context ---
				try {
					$localeLang = $localeLang.call( $localeLang  , $languageContext);
				} catch (ex) {
					// --- execute method ---
				}
				
			}
		} catch ( ex ) {
			$localeLang = $langServContext["default.undefined"];
		}
		
		return $localeLang;
		
	},
	
	/**
	 * set the security for the component 
	 * @param {Object} $comp
	 * @param {Object} $id
	 */
	authComponent:function($comp , $id) {
		
		// --- return rules defined ---
		return $comp;
	}
	
	
};




(function() {
	// set the loader time --
	Vsg.startTime = new Date();	  
})();
